package com.itstyle.seckill.common.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RedPackage {
    public static void main(String[] args) {
        List<Integer> amountList = RedPackage(10000, 5);
        for (Integer amount : amountList) {
            System.out.println("抢到金额：" + new BigDecimal(amount).divide(new BigDecimal(100)) + "元");
        }
    }

    public static List<Integer> RedPackage(int totalAmount, Integer totalPeople) {
        List<Integer> amountList = new ArrayList<>();
        Integer restAmount = totalAmount;
        Integer restPeople = totalPeople;
        Random random = new Random();
        for (int i = 0; i < totalPeople - 1; i++) {
            System.out.println(restPeople);
            // 随机范围：[1,剩余人均金额的两倍]
            int amount = random.nextInt(restAmount / restPeople * 2 - 1) + 1;
            restAmount -= amount;
            restPeople--;
            amountList.add(amount);
        }
        amountList.add(restAmount);
        return amountList;
    }
}
